package com.vsoft.sms_cm;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

import org.apache.log4j.Logger;


import com.vsoft.framework.core.BaseException;
import com.vsoft.framework.core.BusiObj;
import com.vsoft.framework.core.IService;
import com.vsoft.framework.core.db.OperAgent;
import com.vsoft.framework.core.db.SQLArgs;
import com.vsoft.framework.core.util.BOHelper;
import com.vsoft.framework.core.util.LogCollect;

public class Customer implements IService
{
	private static Logger	vLogger		= Logger.getLogger(Customer.class);

	private String				vName			= Customer.class.getName();

	private Connection		vConn			= null;

	private SQLArgs			vArg				= new SQLArgs();

	private BusiObj			vInBO			= null;

	private StringBuffer	vStrBuf				= new StringBuffer();

	private String				staffNo			= "";

	private String				staffCode		= "";

	private String				staffName	= "";

	private String				gSql				= "";
	private final static String		RESULT			="RESULT";
	private CmPublic 		 __CmPublic;
	public BusiObj execute(BusiObj obj) throws BaseException 
	{
		vInBO						=	obj;
		__CmPublic 				= 	new CmPublic(vInBO.getConnection());
		return __CmPublic.execute(this, vInBO);
		 
	}
	/*删除sql in条件等后面多余的","
	 * */
	private String processArgs(String args)
	{
		String ret_value		=	"";
		int	beginIndex		=	0;	
		String	str				=	args.trim();
		ret_value					=	str.substring(beginIndex, str.length()-1);
		return ret_value;
	}
	//输出方法的结果信息到log4j
	private void logFuncRsOutput(String funcName,BusiObj bo ) throws BaseException
	{
		vLogger.info(funcName+":::返回数据是:\n\n\n\n" + BOHelper.boToXML(bo));
	}
	/////////////////根据被叫查询触发电话信息
	public BusiObj getTriggerPhoneByOrderNum(String order_num,Connection conn)throws BaseException
	{
		BusiObj		rsBo 		=	new BusiObj();
		String sql				=	" select * from trigger_phone b " +
										" where b.area_no||b.phone_num=:order_num and b.state='1'";
		SQLArgs 	Arg			= new SQLArgs();
		Arg.setArg("order_num", order_num);
		rsBo 			= OperAgent.execQuery(conn, "getTriggerPhoneByOrderNum", sql, Arg);
		vLogger.info("返回数据是:\n\n\n\n" + BOHelper.boToXML(rsBo));
		return rsBo;
	}
	public  String genSQLINArgs(ArrayList<BusiObj> AlArgs,String ArgName,String ArgType)throws BaseException
	{

		String args ="",argValue="";
		for(BusiObj m:AlArgs)
		{
			argValue	=	m.getString(ArgName);
			if(ArgName.toUpperCase().equals("STRING"))
				args	+="'"+	argValue +"',";
			else
				args	+=	argValue +",";
			//Arg.setArg("sms_temple_id", sms_temple_id);
		}
		args=this.processArgs(args);
		return args;
	}
	public  BusiObj getSmsTempleteBySmsTempleId(ArrayList<String> sms_temple_id,Connection conn)throws BaseException
	{
		BusiObj		rsBo 		=	new BusiObj();
		String sql				=	" select * from sms_templete c " +
										" where c.audit_flag='1' and c.eff_date<=sysdate and c.exp_date>=sysdate " +
										" and c.sms_temple_id in(:sms_temple_id)";
		SQLArgs 	Arg			= new SQLArgs();
		//Customer.genSQLArgs(sms_temple_id, Arg, "sms_temple_id");
		//Arg.setArg("sms_temple_id", sms_temple_id);
		rsBo 			= OperAgent.execQuery(conn, "getSmsTempleteBySmsTempleId", sql, Arg);
		vLogger.info("返回数据是:\n\n\n\n" + BOHelper.boToXML(rsBo));
		return rsBo;
	}
	///////////////////////////////////////根据短信模板id获取短信模板信息
	public  BusiObj getSmsTempleById(BusiObj bo)throws BaseException
	{
		String funcName	=	"getSmsTempleById";
		BusiObj		retBo 		=	new BusiObj();
		
		String cdr_type		=	bo.getString("cdr_type");//add at 20110618   cdr_type
		Connection	conn	=	bo.getConnection();
		String sms_temple_id	="";
		String args="";

		SQLArgs 	Arg			= new SQLArgs();
		
		ArrayList<BusiObj> alSmsTemple	=	bo.getBusiObjList(RESULT);
		if(alSmsTemple.size()<=0)//如果触发电话没有模板，则直接返回
		{
			retBo.setValue(RESULT,new ArrayList<BusiObj>());
			return retBo;
		}else//
		{
/*			for(BusiObj m:alSmsTemple)
			{
				sms_temple_id	=	m.getString("sms_temple_id");
				Arg.setArg("sms_temple_id", sms_temple_id);
			}*/
			args = this.genSQLINArgs(alSmsTemple, "sms_temple_id", "Number");
			
		}
		String sql				=	" select * from sms_templete c " +
										" where c.audit_flag='1' " +// and c.eff_date<=sysdate and c.exp_date>=sysdate
										" and c.sms_temple_id in("+args+") and (c.cdr_type=:cdr_type or c.cdr_type='4')";
		//Customer.genSQLArgs(sms_temple_id, Arg, "sms_temple_id");
		Arg.setArg("cdr_type", cdr_type);
		retBo 			= OperAgent.execQuery(conn, funcName, sql, Arg);
		vLogger.info(funcName+"返回数据是:\n\n\n\n" + BOHelper.boToXML(retBo));
		this.logFuncRsOutput(funcName, retBo);
		return retBo;
	}

	///////////////////////////////////////根据短信模板id获取短信模板信息
	public  BusiObj getTempleGroupById(BusiObj bo)throws BaseException
	{
		String funcName	=	"getTempleGroupById";
		BusiObj		retBo 		=	new BusiObj();
		Connection	conn	=	bo.getConnection();
		String sms_temple_id	="";
		String args ="";

		SQLArgs 	Arg			= new SQLArgs();
		
		ArrayList<BusiObj> alSmsTemple	=	bo.getBusiObjList(RESULT);
		if(alSmsTemple.size()<=0)//如果触发电话没有模板，则直接返回
		{
			retBo.setValue(RESULT,new ArrayList<BusiObj>());
			return retBo;
		}else//
		{

			for(BusiObj m:alSmsTemple)
			{
				sms_temple_id	=	m.getString("sms_temple_id");
				args	+=	sms_temple_id +",";
				//Arg.setArg("sms_temple_id", sms_temple_id);
			}
			args=this.processArgs(args);
			//Arg.setArg("sms_temple_id", args);
			
		}
		//Customer.genSQLArgs(sms_temple_id, Arg, "sms_temple_id");
		String sql				=	" select * from sms_temple_group d " +
										" where d.sms_temple_id in("+args+") ";
		retBo 			= OperAgent.execQuery(conn, funcName, sql, Arg);
		//vLogger.info(funcName+"返回数据是:\n\n\n\n" + BOHelper.boToXML(retBo));
		this.logFuncRsOutput(funcName, retBo);
		return retBo;
	}
	///////////分布查询被叫短信模板信息
	public  BusiObj getCalledSMSTemple(BusiObj bo)throws BaseException
	{
		//TODO  改为分步查询，以便输出不同的错误信息
		BusiObj		rsBo =	new BusiObj();
		String order_num	=	bo.getString("order_num");
		String cdr_type		=	bo.getString("cdr_type");//add at 20110618   cdr_type
		Connection	conn	=	bo.getConnection();
		//1、根据被叫查询触发电话信息
		BusiObj 	triggerBo	= this.getTriggerPhoneByOrderNum(order_num, conn);
		triggerBo.setString("cdr_type", cdr_type);
		triggerBo.setConnection(conn);
		//2、根据触发电话模板查询短信模板信息
		BusiObj 	smsTempleBo	= this.getSmsTempleById(triggerBo);
		smsTempleBo.setConnection(conn);
		//3、根据短信模板查询短信模板群组信息
		BusiObj 	smsTempleGroupBo	= this.getTempleGroupById(smsTempleBo);
		//4、根据短信模板查询订购信息
		
		return smsTempleGroupBo;
	}
	public static BusiObj getSubscriberAndSMSTemple(String order_num,Connection conn)throws BaseException
	{
		
		//1、根据被叫查询触发电话信息
		
		//2、根据触发电话模板查询短信模板信息
		
		//3、根据短信模板查询短信模板群组信息
		
		//4、根据短信模板查询订购信息
/*		String Sql					=	" select a.sub_id sub_id,b.sm_temple_id sm_temple_id,b.sm_temple_context sm_temple_context " +
											" from cm_subscriber a left join cm_sm_templete b on a.sub_id = b.sub_id where a.state='1'  " +
											" and b.eff_time<=sysdate and b.exp_time>=sysdate and b.audit_flag='1' and a.order_num=:order_num";*/
/*		String sql_select			=	" select distinct a.ent_code ent_code,a.order_sn sub_id,c.sms_temple_id sm_temple_id,c.sms_temple_context sm_temple_context, " +
											" d.group_id group_id,d.group_type group_type  ";*/
		String sql_select			=	" select distinct c.ent_code ent_code,a.order_sn sub_id,c.sms_temple_id sm_temple_id,c.sms_temple_context sm_temple_context, " +
											" d.group_id group_id,d.group_type group_type  ";
/*		String sql					=	sql_select +
											" from order_info a,trigger_phone b,sms_templete c,sms_temple_group d " +
											" where b.sms_temple_id = c.sms_temple_id  " +
											" and a.ent_code=c.ent_code and c.audit_flag='1' and c.eff_date<=sysdate and c.exp_date>=sysdate   " +
											" and a.state='1'  and b.state='1' " +
											" and b.area_no||b.phone_num=:order_num " +//20110214 add      b.area_code||
											" and d.sms_temple_id=c.sms_temple_id " +
											" order by c.sms_temple_id,a.order_sn,d.group_type desc ";*/
		String sql					=	sql_select +
											" from order_info a,trigger_phone b,sms_templete c,sms_temple_group d " +
											" where b.sms_temple_id = c.sms_temple_id  " +
											" and a.ent_code=c.ent_code   " +// and c.audit_flag='1' and c.eff_date<=sysdate and c.exp_date>=sysdate
											" and a.state='1' and b.state='1' " +
											" and b.area_no||b.phone_num=:order_num " +//20110214 add      b.area_code||
											" and d.sms_temple_id=c.sms_temple_id " +
											" order by c.sms_temple_id,a.order_sn,d.group_type desc ";
		SQLArgs 	Arg			= new SQLArgs();
		Arg.reset();
		Arg.setArg("order_num", order_num);
		vLogger.info("根据短信触发电话号码、主叫号码查询短信模板和订户id（订购序号） \n sql:" +sql);
		BusiObj		rsBo 			= OperAgent.execQuery(conn, "getSubscriberAndSMSTemple", sql, Arg);
		//如果触发电话找不到，就直接到订购信息里面将付费电话作为触发电话
		if(rsBo.getBusiObjList(RESULT).size()<=0)
		{
/*			sql						=	sql_select+
											" from order_info a,sms_templete c ,sms_temple_group d" +
											" where a.order_sn=c.order_sn and c.audit_flag='1' and c.eff_date<=sysdate and c.exp_date>=sysdate  " +
											" and a.state='1'  and a.area_code||a.vouch_number=:order_num " +
											" and d.sms_temple_id=c.sms_temple_id";*/
			sql						=	sql_select+
											" from order_info a,sms_templete c ,sms_temple_group d" +
											" where a.order_sn=c.order_sn and c.audit_flag='1' and c.eff_date<=sysdate and c.exp_date>=sysdate  " +
											" and a.state='1'  and a.area_code||a.vouch_number=:order_num " +
											" and d.sms_temple_id=c.sms_temple_id";
			Arg.reset();
			Arg.setArg("order_num", order_num);
			rsBo 						= OperAgent.execQuery(conn, "getSubscriberAndSMSTemple", sql, Arg);
		}

		return rsBo;
	}
	//根据主叫号码查询短信模板
	public static BusiObj getSMSTempleByCallingNum(String mobile_num,String ent_code,Connection conn)throws BaseException
	{
		// 	GROUP_TYPE： 0：默认；1，客户群组；2：企业白名单
		String 		sql			=	" ";
		
		 		sql					=	" select  t.sms_temple_id sms_temple_id,t.group_type group_type,t.group_id group_id  from (" +
		 									" select distinct d.sms_temple_id sms_temple_id,d.group_type group_type,d.group_id group_id " +
											" from customer a ,cust_group_member b,customer_group c,sms_temple_group d " +
											" where a.mobile_num=:mobile_num and a.cust_code=b.cust_code and b.group_id=c.group_id " +
											" and c.group_id = d.group_id and a.ent_code =:ent_code and a.cust_type ='1'" +
											" union " +
											" select distinct 0 sms_temple_id,a1.cust_type group_type,0 group_id" +
											" from  customer a1 " +
											" where a1.mobile_num=:mobile_num and a1.ent_code =:ent_code and a1.cust_type ='2' " +
											" union " +
											" select distinct c.sms_temple_id sms_temple_id,c.group_type group_type,c.group_id group_id" +
											" from order_info a ,sms_templete b ,sms_temple_group c " +
											" where a.order_sn = b.order_sn and a.state='1' and b.audit_flag='1' and b.state='1' " +
											" and b.sms_temple_id = c.sms_temple_id and c.group_type='0' and a.ent_code=:ent_code)t " +
											" order by  t.group_type desc" +
											"  ";
		SQLArgs 	Arg			= new SQLArgs();
		Arg.reset();
		Arg.setArg("mobile_num", mobile_num);
		Arg.setArg("ent_code", ent_code);
		BusiObj		rsBo 			= OperAgent.execQuery(conn, "getSMSTempleByCallingNum", sql, Arg);
		return rsBo;
	}
	//根据短信模板查询
	public static BusiObj getSMSTempleForSearchAll(String mobile_num,Connection conn)throws BaseException
	{
		// 	GROUP_TYPE： 0：默认；1，客户群组；2：企业白名单
		String 		sql			=	" select distinct d.sms_temple_id sms_temple_id,c.group_type c.group_type from customer a ,cust_group_member b,customer_group c,sms_temple_group d " +
											" where a.mobile_num=:mobile_num and a.cust_code=b.cust_code and b.group_id=c.group_id and c.group_id = d.group_id";
		SQLArgs 	Arg			= new SQLArgs();
		Arg.reset();
		Arg.setArg("mobile_num", mobile_num);
		BusiObj		rsBo 			= OperAgent.execQuery(conn, "getSMSTempleByCallingNum", sql, Arg);
		return rsBo;
	}
	//根据号码查询短信模板和订户id（订购序号）
	public  BusiObj getSubscriberAndSMSTemple(BusiObj bo)throws BaseException
	{
		String order_num	=	bo.getString("order_num");
		Connection	conn	=	bo.getConnection();
		return Customer.getSubscriberAndSMSTemple(order_num, conn);
	}
	//根据短信触发电话号码、主叫号码查询短信模板和订户id（订购序号）
	public  BusiObj getSMSTempleService(BusiObj bo)throws BaseException
	{
		return Customer.getSMSTemple(bo);
	}
	//根据短信触发电话号码、主叫号码查询短信模板和订户id（订购序号）
	public static BusiObj getSMSTemple(BusiObj bo)throws BaseException
	{
/*		String order_num	=	bo.getString("order_num");
		String mobile_num	=	bo.getString("mobile_num");
		String cdr_type		=	bo.getString("cdr_type");//add at 20110618   cdr_type
		Connection	conn	=	bo.getConnection();*/
		BusiObj		retBo	=	new BusiObj();
		retBo					=	TableCacheServer.getTempleForSend(bo);
		return retBo;
/*		String	ent_code	=	"";
		//根据触发电话查模板
		BusiObj 	smsTempleBo	= Customer.getSubscriberAndSMSTemple(order_num, conn);
		ArrayList<BusiObj> alSmsTemple	=	smsTempleBo.getBusiObjList(RESULT);
		if(alSmsTemple.size()<=0)//如果触发电话没有模板，则直接返回
		{
			retBo.setValue(RESULT,new ArrayList<BusiObj>());
			return retBo;
		}else//一个触发电话只属于一个企业
		{
			ent_code	=	alSmsTemple.get(0).getString("ent_code");
		}
		//根据主叫查模板
		BusiObj		smsBo	=	Customer.getSMSTempleByCallingNum(mobile_num,ent_code, conn);

		
		
		ArrayList<BusiObj> alSms				=	smsBo.getBusiObjList(RESULT);
		
		String whiteTempleId="";
		HashMap<String,String> hAddedTempleId= new HashMap<String,String>();
		for(BusiObj smsTemple:alSmsTemple)
		{
			String smsTempleId	=	smsTemple.getString("sm_temple_id");
			String group_id	=	smsTemple.getString("group_id");
			String group_type	=	smsTemple.getString("group_type");
			if(group_type.equals("2"))//group_type=2是白名单，在此过滤
			{
				
				continue;
			}
			//else 
			boolean	whiteFlag=false;//白名单标志 
			for(BusiObj sms:alSms)
			{
				String sms_group_type=sms.getString("group_type");
				String sms_temple_id=sms.getString("sms_temple_id");
				if(sms_group_type.equals("2"))//group_type=2是白名单，在此过滤
				{
					whiteTempleId = smsTempleId;
					whiteFlag	=	true;//设置白名单标志，只要这个电话是企业白名单，就跳过，白名单与模板无关
					break;
				}
				if(sms_temple_id.equals(whiteTempleId))//如果模板id=前面白名单的模板id，则过滤，因此要求前面sql的排序
					continue;
				if(sms_group_type.equals("0"))//group_type=0是默认群组，直接加上
				{
					if(hAddedTempleId.get(sms_temple_id)==null)
					{
						retBo.setValue(RESULT, smsTemple);
						hAddedTempleId.put(sms_temple_id, sms_temple_id);
					}
					continue;//相同的记录只打一条
				}
				if(sms_group_type.equals("1")
					&&
						(
								smsTempleId.equals(sms_temple_id)
								&&	group_id.equals(sms.getString("group_id"))
						)
					)
					//客户群组，则要与根据被叫找到的模板和模板群组信息比较模板与群组id
				{
					if(hAddedTempleId.get(sms_temple_id)==null)
					{
						retBo.setValue(RESULT, smsTemple);
						hAddedTempleId.put(sms_temple_id, sms_temple_id);
					}
					continue;//相同的记录只打一条
				}

			}
			if(group_type.equals("0")&& !whiteFlag)//group_type=0是默认群组，并且主叫不是白名单，在此打入
			{
				if(hAddedTempleId.get(smsTempleId)==null)
				{
					retBo.setValue(RESULT, smsTemple);
					hAddedTempleId.put(smsTempleId, smsTempleId);//要考虑主叫号码是白名单的情况
				}
				continue;
			}
		}
		if(retBo.getRawData().isEmpty())
		{
			retBo.setValue(RESULT,new ArrayList<BusiObj>());
		}
		//if(retBo.getBusiObjList(RESULT).size()<=0){}
			
		
		return retBo;*/
	}
	@Deprecated
	public BusiObj setCustomerBak(BusiObj bo)throws BaseException
	{
		String	tableName	=	"customer";
		String	listName		=	"customerList";
		ArrayList<BusiObj> member = bo.getBusiObjList(listName);
		bo.setValue(tableName, member);
		Connection conn = bo.getConnection();
		BusiObj retBO	=	new BusiObj();
		retBO	=	__CmPublic.commonSetTablesForMulti(bo);
		return retBO;
	}
	//设置企业客户信息
	public BusiObj setCustomer(BusiObj bo)throws BaseException
	{
		BusiObj retBO	=	new BusiObj();
		String	tableName	=	"customer";
		String	listName		=	"customerList";
		//ArrayList<BusiObj> member = bo.getBusiObjList(listName);
		//bo.setValue(tableName, member);
		//String   ent_code 					= bo.getString("ent_code", "");
		HashMap<String,String>hCol	=	new HashMap<String,String>();
		hCol							=	__CmPublic.genCommonCols();
		String	create_time		=	CmPublic.getSysdate();	
		hCol.put("create_time", create_time);
		//hCol.put("ent_code", ent_code);
		//hCol.put("operator", staffNo);
		//retBO	=	__CmPublic.commonSetTablesForMulti(bo);
		__CmPublic.setTableData(bo, listName, tableName,hCol);

		retBO.setValue("ResultFlag", "0");
		return retBO;
	}
	//设置短信模板触发电话信息
	public BusiObj setTriggerPhone(BusiObj bo)throws BaseException
	{
		BusiObj retBO	=	new BusiObj();
		String	tableName	=	"trigger_phone";
		String	listName		=	"triggerPhoneList";

		HashMap<String,String>hCol	=	new HashMap<String,String>();
		hCol							=	__CmPublic.genCommonCols();
		String	create_time		=	CmPublic.getSysdate();	
		hCol.put("create_time", create_time);

		__CmPublic.setTableData(bo, listName, tableName,hCol);

		retBO.setValue("ResultFlag", "0");
		return retBO;
	}
	//设置企业客户群组信息
	public BusiObj setCustomerGroup(BusiObj bo)throws BaseException
	{
		BusiObj retBO	=	new BusiObj();
		String	tableName	=	"customer_group";
		String	listName		=	"customerGroupList";

		HashMap<String,String>hCol	=	new HashMap<String,String>();
		hCol							=	__CmPublic.genCommonCols();

		String	create_time		=	CmPublic.getSysdate();	
		hCol.put("create_time", create_time);
		//add at 20120529
		hCol		=	__CmPublic.removeCols(hCol, bo,listName);
		vLogger.info("===========common cols is"+hCol);
		__CmPublic.setTableData(bo, listName, tableName,hCol);

		retBO.setValue("ResultFlag", "0");
		return retBO;
	}
	//设置模板规则
	public BusiObj setSmsTempleRulesReal(BusiObj bo)throws BaseException
	{
		BusiObj retBO	=	new BusiObj();
		String	tableName	=	"sms_temple_rules_real";
		String	listName		=	"smsTempleRulesRealList";

		HashMap<String,String>hCol	=	new HashMap<String,String>();
		hCol							=	__CmPublic.genCommonCols();
		String	create_time		=	CmPublic.getSysdate();	
		hCol.put("create_time", create_time);

		__CmPublic.setTableData(bo, listName, tableName,hCol);

		retBO.setValue("ResultFlag", "0");
		return retBO;
	}
	//设置企业客户群组信息
	public BusiObj setCustomerGroupMember(BusiObj bo)throws BaseException
	{
		BusiObj retBO	=	new BusiObj();
		String	tableName	=	"cust_group_member";
		String	listName		=	"customerGroupMemberList";

		HashMap<String,String>hCol	=	new HashMap<String,String>();
		hCol							=	__CmPublic.genCommonCols();
		String	create_time		=	CmPublic.getSysdate();	
		hCol.put("create_time", create_time);
		__CmPublic.setTableData(bo, listName, tableName,hCol);

		retBO.setValue("ResultFlag", "0");
		return retBO;
	}
	//设置短信模板群组信息
	public BusiObj setSmsTempleGroup(BusiObj bo)throws BaseException
	{
		BusiObj retBO	=	new BusiObj();
		String	tableName	=	"sms_temple_group";
		String	listName		=	"smsTempleGroupList";

		HashMap<String,String>hCol	=	new HashMap<String,String>();
		hCol							=	__CmPublic.genCommonCols();
		String	create_time		=	CmPublic.getSysdate();	
		hCol.put("create_time", create_time);
		__CmPublic.setTableData(bo, listName, tableName,hCol);

		retBO.setValue("ResultFlag", "0");
		return retBO;
	}
	//设置企业信息
	public BusiObj setEnterprise(BusiObj bo)throws BaseException
	{
		BusiObj retBO	=	new BusiObj();
		String	tableName	=	"enterprise";
		String	listName		=	"enterpriseList";

		HashMap<String,String>hCol	=	new HashMap<String,String>();
		hCol							=	__CmPublic.genCommonCols();
		String	create_time		=	CmPublic.getSysdate();	
		hCol.put("create_time", create_time);
		//hCol.put("operator", staffNo);
		//add at 20120529
		hCol		=	__CmPublic.removeCols(hCol, bo,listName);
		vLogger.info("===========common cols is"+hCol);
		__CmPublic.setTableData(bo, listName, tableName,hCol);
		//1.delete 
		//2.insert
		retBO.setValue("ResultFlag", "0");
		return retBO;
	}
	//设置定价计划实例，在订购的时候（即crm接口）
	public BusiObj setPricePlanInst(BusiObj bo)throws BaseException
	{
		BusiObj retBO	=	new BusiObj();
		String	tableName	=	"PRICE_PLAN_INST";
		String	listName		=	"pricePlanInstList";

		HashMap<String,String>hCol	=	new HashMap<String,String>();
		hCol							=	__CmPublic.genCommonCols();
		String	create_time		=	CmPublic.getSysdate();	
		hCol.put("created_DATE", create_time);
		hCol.put("STATE_DATE", create_time);
		hCol.put("UPDATE_DATE", create_time);
		hCol.put("COMPLETED_DATE", create_time);
		//hCol.put("operator", staffNo);
		__CmPublic.setTableData(bo, listName, tableName,hCol);
		//1.delete 
		//2.insert
		retBO.setValue("ResultFlag", "0");
		return retBO;
	}

	public BusiObj setIndustryType(BusiObj bo)throws BaseException
	{
		vLogger.info("输入数据是:\n" + BOHelper.boToXML(bo));
		BusiObj retBO	=	new BusiObj();
		String	tableName	=	"industry_type";
		String	listName		=	"industryList";
		__CmPublic.setTableData(bo, listName, tableName,null);
		retBO.setValue("ResultFlag", "0");
		return retBO;
	}
	public BusiObj setBureau(BusiObj bo)throws BaseException
	{
		BusiObj retBO	=	new BusiObj();
		String	tableName	=	"BUREAU";
		String	listName		=	"BureauList";
		__CmPublic.setTableData(bo, listName, tableName,null);
		retBO.setValue("ResultFlag", "0");
		return retBO;
	}
	public BusiObj setSocialType(BusiObj bo)throws BaseException
	{
		BusiObj retBO	=	new BusiObj();
		String	tableName	=	"social_type";
		String	listName		=	"socialtypeList";
		__CmPublic.setTableData(bo, listName, tableName,null);
		retBO.setValue("ResultFlag", "0");
		return retBO;
	}
	public BusiObj getAllIndustryType(BusiObj bo)throws BaseException
	{
		String tableName		=	"industry";
		return __CmPublic.getSimpleTableData(bo, tableName);
	}
	public BusiObj getAllBureau(BusiObj bo)throws BaseException
	{
		String tableName		=	"BUREAU";
		return __CmPublic.getSimpleTableData(bo, tableName);
	}
	public BusiObj getAllSocialType(BusiObj bo)throws BaseException
	{
		String tableName		=	"social_type";
		return __CmPublic.getSimpleTableData(bo, tableName);
	}
	public BusiObj getEntprise(BusiObj bo)throws BaseException
	{
		String tableName		=	"enterprise";
		return __CmPublic.getSimpleTableData(bo, tableName);
	}
	public BusiObj getEntpriseSelf(BusiObj bo)throws BaseException
	{
		String tableName		=	"enterprise";
		HashMap<String,String> hCondition=	new 	HashMap<String,String>();
		String	conditionCol=	"ENT_CODE";
		String	ENT_CODE	=	bo.getString(conditionCol);
		hCondition.put(conditionCol,ENT_CODE);
		return __CmPublic.getSimpleTableDataWithCondition(bo, tableName,hCondition);
	}


	//根据企业查询客户信息
	public BusiObj getCustomerByEnt(BusiObj bo)throws BaseException
	{
		String tableName		=	"customer";
		String	listName		=	"productPropsList";
		HashMap<String,String> hCondition=	new 	HashMap<String,String>();

		String	conditionCol=	"ENT_CODE";
		String	ENT_CODE	=	bo.getString(conditionCol);
		hCondition.put(conditionCol,ENT_CODE);
		conditionCol=	"CUST_TYPE";
		String	CUST_TYPE	=	bo.getString(conditionCol);
		hCondition.put(conditionCol,CUST_TYPE);//客户类型:1：普通客户；2：企业白名单
		return __CmPublic.getSimpleTableDataWithCondition(bo, tableName,hCondition);
	}
}

